package com.ih.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ih.pojo.Salary;
import com.ih.pojo.Worker;
import com.ih.service.SalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/salary")
@Slf4j
public class SalaryController {
    @Autowired
    private SalaryService salaryService;
    /**
     * 模糊查询带分页
     * @param pageNum
     * @param pageSize
     * @param worker
     * @param model
     * @return
     */
    @RequestMapping("/searchCalcSalay")
    public String listSalry(@RequestParam(required = false,defaultValue = "1",value = "pageNum") Integer pageNum,
                           @RequestParam(required = false,defaultValue = "10",value = "pageSize") Integer pageSize,
                            Worker worker, Model model,String startDate,String endDate) {
        if (pageNum==null||pageNum<=0 || pageNum.equals("")){
            pageNum=1;
        }
        if (pageSize==null||pageSize<=0 || pageSize.equals("")){
            pageSize=10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.calcSalaryByCondition(startDate, endDate, pageNum, pageSize);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("startDate", startDate);
        model.addAttribute("endDate", endDate);
        return "salaryList";
    }

    /**
     * 模糊查询带分页
     * @param pageNum
     * @param pageSize
     * @param worker
     * @param model
     * @return
     */
    @RequestMapping("/IsNullWorker")
    public String IsNullWorker(@RequestParam(required = false,defaultValue = "1",value = "pageNum") Integer pageNum,
                            @RequestParam(required = false,defaultValue = "10",value = "pageSize") Integer pageSize,
                            Worker worker, Model model) {
        if (pageNum==null||pageNum<=0 || pageNum.equals("")){
            pageNum=1;
        }
        if (pageSize==null||pageSize<=0 || pageSize.equals("")){
            pageSize=10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.IsNullWorker(pageNum, pageSize);
        model.addAttribute("pageInfo", pageInfo);
        return "salaryList";
    }
}
